package com.lmbx.shzh.controller;

import com.lmbx.shzh.domain.common.ResponseResult;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.WebRequest;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class test {
//    @ApiOperation("预报雨量")
//    @GetMapping("/getRain")
//    public ResponseResult getRain() {
//        return service.getRain();
//    }
//
//    @ApiOperation("实时雨情统计")
//    @GetMapping("/getRainNum")
//    public ResponseResult getRainNum() {
//        return service.getRainNum();
//    }
//    /**
//     * 雨量超警
//     * @param tm
//     * @return
//     */
//    @ApiOperation("雨量超警列表")
//    @GetMapping("/getRainTown")
//    public ResponseResult getRainTown(
//            @ApiParam(name = "vCode",value = "地区编码",example = "1301") @RequestParam("vCode") String vCode,
//            @ApiParam(name = "hour",value = "时间范围",example = "1") @RequestParam("hour")  @Min(value = 1, message = "时间范围不合法，最小为1") @Max(value = 24, message = "时间范围不合法，最大为24") int hour){
//
//        return service.getRainTown(vCode, hour);
//    }
//
//    @ApiOperation("水库水情1")
//    @GetMapping("/getRsvrAll")
//    public ResponseResult getRsvrAll() {
//        return service.getRsvrAll();
//    }
//
//    @ApiOperation("水库水情2")
//    @GetMapping("/getRsvr")
//    public ResponseResult getRsvr() {
//        return service.getRsvr();
//    }
//
//    @ApiOperation("河道水情1")
//    @GetMapping("/getRsverAll")
//    public ResponseResult getRsverAll() {
//        return service.getRsverAll();
//    }
//
//    @ApiOperation("河道水情2")
//    @GetMapping("/getRsver")
//    public ResponseResult getRsver() {
//        return service.getRsver();
//    }
//
//    @ApiOperation("山洪预警")
//    @GetMapping("/getWarnInfo")
//    public ResponseResult getWarnInfo() {
//        return service.getWarnInfo();
//    }
//
//    @ApiOperation("预报预警")
//    @GetMapping("/getRainFull")
//    public ResponseResult getRainFull() {
//        return service.getRainFull();
//    }
//    @InitBinder
//    public void initBinder(WebDataBinder binder, WebRequest request) {
//        //转换日期 注意这里的转化要和传进来的字符串的格式一直 如2015-9-9 就应该为yyyy-MM-dd
//        DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器
//    }
// <!--预报雨量-->
//    <select id="getRain" resultType="java.util.HashMap">
//--         SELECT top 10 D.STCD,D.STNM,F.ADNM sheng,E.ADNM shi,G.ADNM xian,SUM(T.DRP) drp,A.drp as drp1,B.drp as drp2,C.drp  as drp3,D.LGTD,D.LTTD
//--         FROM HBS_RTDB_HB.DBO.ST_PPTN_R T
//--         LEFT JOIN (SELECT A.STCD,SUM(A.DRP) DRP FROM HBS_RTDB_HB.DBO.st_pptn_r A,HBS_RTDB_HB.DBO.st_pptn_r B  WHERE A.STCD=B.STCD
//--         AND A.TM>DATEADD(HH,-1,B.TM)  AND A.TM &lt;=B.TM   and datediff(day,a.tm,getdate()) = 0 GROUP BY A.STCD) A ON T.STCD=A.STCD
//--         LEFT JOIN (SELECT A.STCD,SUM(A.DRP) DRP FROM HBS_RTDB_HB.DBO.st_pptn_r A,HBS_RTDB_HB.DBO.st_pptn_r B
//--         WHERE A.STCD=B.STCD AND A.TM>DATEADD(HH,-2,B.TM)  AND A.TM &lt;=B.TM   and datediff(day,a.tm,getdate()) = 0
//--         GROUP BY A.STCD) B ON T.STCD=B.STCD
//--         LEFT JOIN (SELECT A.STCD,SUM(A.DRP) DRP FROM HBS_RTDB_HB.DBO.st_pptn_r A,HBS_RTDB_HB.DBO.st_pptn_r B
//--         WHERE A.STCD=B.STCD
//--         AND A.TM>DATEADD(HH,-3,B.TM)
//--         AND A.TM &lt;=B.TM
//--         and datediff(day,a.tm,getdate()) = 0
//--         GROUP BY A.STCD) C ON T.STCD=C.STCD
//--         left join  HBS_RTDB_HB.DBO.ST_STBPRP_b D ON T.STCD=D.STCD
//--         LEFT JOIN AD_CD_B g on D.ADDVCD+'000000000'=g.ADCD
//--         LEFT JOIN AD_CD_B E on SUBSTRING(D.ADDVCD, 0, 5)+'00000000000'=E.ADCD
//--         LEFT JOIN AD_CD_B F on SUBSTRING(D.ADDVCD, 0, 3)+'0000000000000'=F.ADCD
//--         WHERE 1=1
//--         AND D.ADDVCD like '${ad}%'
//--         and datediff(day,tm,getdate()) = 0
//--         GROUP BY D.STCD,F.ADNM,E.ADNM,g.ADNM,A.drp,B.drp,C.drp,D.BSNM,D.FRGRD,D.HNNM,D.LGTD,D.LTTD,D.RVNM,D.STLC,  D.STNM,D.STTP
//--         order by D.STCD
//        select TOP 10 AD.ADNM,S.STCD,S.LGTD,S.LTTD,T.DRP from AD_CD_B ad
//        LEFT JOIN ST_STBPRP_B S ON SUBSTRING(S.ADDVCD, 1, 2) = SUBSTRING(AD.ADCD, 1, 2)
//        left JOIN ST_PPTN_R T on S.STCD = T.STCD
//        LEFT JOIN (SELECT A.STCD,SUM(A.DRP) DRP FROM st_pptn_r A,st_pptn_r B  WHERE A.STCD=B.STCD
//        AND A.TM &lt;=B.TM AND A.tm BETWEEN DATEADD(HOUR,-1,GETDATE()) and GETDATE() GROUP BY A.STCD)
//        LEFT JOIN (SELECT A.STCD,SUM(A.DRP) DRP FROM st_pptn_r A,st_pptn_r B  WHERE A.STCD=B.STCD
//        AND A.TM &lt;=B.TM AND A.tm BETWEEN DATEADD(HOUR,-2,GETDATE()) and GETDATE() GROUP BY A.STCD)
//        LEFT JOIN (SELECT A.STCD,SUM(A.DRP) DRP FROM st_pptn_r A,st_pptn_r B  WHERE A.STCD=B.STCD
//        AND A.TM &lt;=B.TM AND A.tm BETWEEN DATEADD(HOUR,-3,GETDATE()) and GETDATE() GROUP BY A.STCD)
//
//
//
//
//
//    </select>
//    <!--实时雨情统计-->
//    <select id="getRainNum" resultType="java.util.HashMap">
//        select g.ADNM,count(a.drp) drp1,count(b.drp) drp2,count(c.drp) drp3,count(d.drp) drp4,count(e.drp) drp5 from HBS_RTDB_HB.DBO.ST_STBPRP_B f
//        LEFT JOIN(select r.STCD,sum(r.DRP) drp from HBS_RTDB_HB.dbo.ST_PPTN_R r where drp>0.1 and drp &lt;=10  and datediff(day,tm,getdate()) = 0 GROUP BY stcd) a
//        on a.stcd = f.STCD
//        LEFT JOIN(select r.STCD,sum(r.DRP) drp from HBS_RTDB_HB.dbo.ST_PPTN_R r where drp>10 and drp &lt;=50  and datediff(day,tm,getdate()) = 0 GROUP BY stcd) b
//        on b.stcd = f.STCD
//        LEFT JOIN(select r.STCD,sum(r.DRP) drp from HBS_RTDB_HB.dbo.ST_PPTN_R r where drp>50 and drp &lt;=100  and datediff(day,tm,getdate()) = 0 GROUP BY stcd) c
//        on c.stcd = f.STCD
//        LEFT JOIN(select r.STCD,sum(r.DRP) drp from HBS_RTDB_HB.dbo.ST_PPTN_R r where drp>100 and drp &lt;=200  and datediff(day,tm,getdate()) = 0 GROUP BY stcd) d
//        on d.stcd = f.STCD
//        LEFT JOIN(select r.STCD,sum(r.DRP) drp from HBS_RTDB_HB.dbo.ST_PPTN_R r where drp>=200  and datediff(day,tm,getdate()) = 0 GROUP BY stcd) e
//        on e.stcd = f.STCD
//        LEFT JOIN AD_CD_B g on SUBSTRING(f.ADDVCD, 0, 5)+'00000000000'=g.ADCD
//        where 1=1
//        and f.ADDVCD like '${ad}%'
//        GROUP BY g.ADNM
//    </select>
//    <!--雨量超警-->
//    <select id="getRainTown" resultType="java.util.HashMap">
//        with RAIN_DATA as
//        (select TOP (100) PERCENT h.addvcd,count(b.drp) drp1,count(c.drp) drp3,count(d.drp) drp6 from
//            HBS_RTDB_HB.DBO.ST_STBPRP_b h
//            left join (	select d.STCD,d.drp from (select stcd,SUM(DRP) as drp from HBS_RTDB_HB.DBO.st_pptn_r
//				where tm BETWEEN DATEADD(HOUR,-1,DATEADD(HH,-1,GETDATE())) and GETDATE()
//				GROUP BY STCD) d where d.drp >30 ) b on h.STCD = b.stcd
//            left join (	select d.STCD,d.drp from (select stcd,SUM(DRP) as drp from HBS_RTDB_HB.DBO.st_pptn_r
//				where tm BETWEEN DATEADD(HOUR,-3,DATEADD(HH,-1,GETDATE())) and GETDATE()
//				GROUP BY STCD) d where d.drp >50 ) c on h.STCD = c.stcd
//            left join (	select d.STCD,d.drp from (select stcd,SUM(DRP) as drp from HBS_RTDB_HB.DBO.st_pptn_r
//				where tm BETWEEN DATEADD(HOUR,-6,DATEADD(HH,-1,GETDATE())) and GETDATE()
//				GROUP BY STCD) d where  d.drp>100 ) d on h.STCD = d.stcd
//            where h.addvcd is not null
//            group by h.ADDVCD
//        )
//        select B.ADNM,sum(A.drp1) drp1, sum(A.drp3) drp3, sum(A.drp6) drp6 from
//        (SELECT ADNM,ADCD from AD_CD_B where LEVELCODE =#{vCodeLevel} and SUBSTRING(ADCD,1,${vCodeLength}) =#{vCode}) B
//        left join RAIN_DATA A on SUBSTRING(A.addvcd,1,2+${vCodeLength})=SUBSTRING(B.ADCD,1,2+${vCodeLength})
//        where B.ADNM is not null
//        group by B.ADNM
//        order by drp1 desc
//    </select>
//    <!--水库水情1-->
//    <select id="getRsvrAll" resultType="java.util.HashMap">
//        select DISTINCT ad.ADNM,stb.STNM,a.RZ,rsv.FSLTDW,A.RZ-rsv.FSLTDZ ZWARN,STB.LTTD,STB.LGTD from HBS_RTDB_HB.DBO.ST_RSVR_R A
//				left join HBS_RTDB_HB.DBO.ST_STBPRP_B STB ON a.STCD=STB.STCD
//				 LEFT JOIN AD_CD_B AD ON SUBSTRING(STB.ADDVCD,0,5)+'00000000000'=AD.ADCD
//        LEFT JOIN HBS_RTDB_HB.DBO.ST_RSVRFCCH_B F on F.STCD=A.STCD
//				left join HBS_RTDB_HB.DBO.ST_RSVRFSR_B rsv on rsv.STCD=a.stcd
//				WHERE sttp ='RR'
//        AND STB.ADDVCD LIKE '${ad}%'
//		and datediff(day,tm,getdate()) = 0
//        AND A.RZ-rsv.FSLTDZ >0
//
//        ORDER BY ZWARN DESC
//    </select>
//    <!--水库水位2-->
//    <select id="getRsvr" resultType="java.util.HashMap">
//        select COUNT(B.STCD) minRsvr,COUNT(C.STCD)maxRsvr,COUNT(d.STCD) maxRsver,AD.ADNM from
//        (select B.STCD from HBS_RTDB_HB.DBO.ST_RSVR_R b,HBS_RTDB_HB.DBO.ST_RSVRFSR_B F
//        where 1=1
//        and b.STCD = f.STCD
//        and datediff(day,tm,getdate()) = 0
//        and b.RZ-f.FSLTDZ >= 0) B
//        LEFT JOIN(select B.STCD from HBS_RTDB_HB.DBO.ST_RSVR_R b,HBS_RTDB_HB.DBO.ST_RSVRFSR_B F
//        where 1=1
//        and b.STCD = f.STCD
//        and datediff(day,tm,getdate()) = 0
//        and b.RZ-f.FSLTDZ &lt; 0) C ON b.STCD=C.STCD
//        LEFT JOIN(select B.STCD from HBS_RTDB_HB.DBO.ST_RSVR_R b,HBS_RTDB_HB.DBO.ST_RSVRFCCH_B F
//        where 1=1
//        and b.STCD = f.STCD
//        and datediff(day,tm,getdate()) = 0
//        and b.RZ-f.CKFLZ > 0) d ON b.STCD=d.STCD
//        LEFT JOIN HBS_RTDB_HB.DBO.ST_STBPRP_B STB ON b.STCD=STB.STCD
//        LEFT JOIN AD_CD_B AD ON SUBSTRING(STB.ADDVCD,0,5)+'00000000000'=AD.ADCD
//        WHERE
//        AD.ADCD LIKE '${ad}%'
//        GROUP BY AD.ADNM
//    </select >
//    <!--河道水情1-->
//    <select id="getRsverAll" resultType="java.util.HashMap">
//         select A.STCD ,STB.STNM,A.Z,WRZ,stb.RVNM,Z-WRZ ZWARN ,STB.LTTD,STB.LGTD,AD.ADNM,WPTN,FRGRD,STTP from
//        (select stcd ,max(tm) tm from HBS_RTDB_HB.DBO.ST_RIVER_R  WHERE  1=1
//       and datediff(day,tm,getdate()) = 0
//        group by stcd) t
//        left join HBS_RTDB_HB.DBO.ST_RIVER_R A on A.STCD=t.STCD and A.TM=t.tm
//        LEFT JOIN HBS_RTDB_HB.DBO.ST_STBPRP_B STB ON a.STCD=STB.STCD
//        LEFT JOIN AD_CD_B AD ON SUBSTRING(STB.ADDVCD,0,5)+'00000000000'=AD.ADCD
//        left join HBS_RTDB_HB.DBO.ST_RVFCCH_B fh on a.STCD=fh.STCD
//        WHERE (sttp ='ZQ' OR STTP='ZZ' OR STTP='QQ')
//         AD.ADCD LIKE '${ad}%'
//        ORDER BY ZWARN desc
//
//
//    </select>
//    <!--河道水情2-->
//    <select id="getRsver" resultType="java.util.HashMap">
//        select count(a.STCD) minRiver,count(b.STCD) maxRiver,COUNT(c.STCD) maxrivers from  HBS_RTDB_HB.DBO.ST_STBPRP_B STB
//        LEFT JOIN ( select a.STCD,z-WRZ zwrz from HBS_RTDB_HB.DBO.ST_RIVER_R a,HBS_RTDB_HB.DBO.ST_RVFCCH_B fh where a.STCD=fh.STCD
//        and datediff(day,tm,getdate()) = 0
//        and a.z-fh.GRZ &lt; 0) a ON a.STCD=STB.STCD
//        left join (
//        select a.STCD,z-WRZ zwrz from HBS_RTDB_HB.DBO.ST_RIVER_R a,HBS_RTDB_HB.DBO.ST_RVFCCH_B fh where a.STCD=fh.STCD
//        and datediff(day,tm,getdate()) = 0
//        and a.z-fh.GRZ>=0) b on stb.STCD=b.STCD
//        left join (
//        select a.STCD,z-WRZ zwrz from HBS_RTDB_HB.DBO.ST_RIVER_R a,HBS_RTDB_HB.DBO.ST_RVFCCH_B fh where a.STCD=fh.STCD
//        and datediff(day,tm,getdate()) = 0
//        and a.z-fh.GRQ>=0) c on stb.STCD=c.STCD
//        LEFT JOIN AD_CD_B AD ON SUBSTRING(STB.ADDVCD,0,5)+'00000000000'=AD.ADCD
//        where
//        ad.ADCD like '${ad}%'
//    </select>
//    <!--山洪预警-->
//    <select id="getWarnInfo" resultType="java.util.HashMap">
//        select e.ADNM shi,f.ADNM sheng,d.ADNM xian,a.WarnSTM,c.WarnStatusNM,b.WarnGradeNM,a.LGTD,a.LTTD from WARNRECORD_R a
//        left join WARNINGGRADE_B b on a.WarnGradeID = b.WarnGradeID
//        left join WARNINGSTATUS_B c on a.WarnStatusID=c.WarnStatusID
//        left join AD_CD_B d on a.ADCD=d.ADCD
//        left join AD_CD_B e on SUBSTRING(a.ADCD,0,3)+'0000000000000'=e.ADCD
//        left join AD_CD_B f on SUBSTRING(a.ADCD,0,5)+'00000000000'=f.ADCD
//
//        where 1=1
//        and d.ADCD LIKE '${ad}%'
//        and datediff(day,a.WarnSTM,getdate()) = 0
//        order by a.WarnSTM
//    </select>
//    <!--中间地图指标-->
//    <select id="getRainFull" resultType="java.util.HashMap">
//        SELECT D.STCD,D.STNM,F.ADNM sheng,E.ADNM shi,G.ADNM xian,D.STTP,SUM(T.DRP) drp,A.drp as drp1,B.drp as drp2,C.drp  as drp3, D.BSNM,D.FRGRD,D.HNNM,D.LGTD,D.LTTD,D.RVNM,D.STLC  FROM HBS_RTDB_HB.DBO.ST_PPTN_R T
//        LEFT JOIN (SELECT A.STCD,SUM(A.DRP) DRP FROM HBS_RTDB_HB.DBO.st_pptn_r A,HBS_RTDB_HB.DBO.st_pptn_r B WHERE A.STCD=B.STCD AND A.TM>DATEADD(HH,-1,B.TM) AND A.TM &lt;=B.TM GROUP BY A.STCD) A ON T.STCD=A.STCD
//        LEFT JOIN (SELECT A.STCD,SUM(A.DRP) DRP FROM HBS_RTDB_HB.DBO.st_pptn_r A,HBS_RTDB_HB.DBO.st_pptn_r B WHERE A.STCD=B.STCD AND A.TM>DATEADD(HH,-3,B.TM) AND A.TM &lt;=B.TM GROUP BY A.STCD) B ON T.STCD=B.STCD
//        LEFT JOIN (SELECT A.STCD,SUM(A.DRP) DRP FROM HBS_RTDB_HB.DBO.st_pptn_r A,HBS_RTDB_HB.DBO.st_pptn_r B WHERE A.STCD=B.STCD AND A.TM>DATEADD(HH,-6,B.TM) AND A.TM &lt;=B.TM GROUP BY A.STCD) C ON T.STCD=C.STCD
//        left join  HBS_RTDB_HB.DBO.ST_STBPRP_b D ON T.STCD=D.STCD
//        LEFT JOIN AD_CD_B g on D.ADDVCD+'000000000'=g.ADCD
//        LEFT JOIN AD_CD_B E on SUBSTRING(D.ADDVCD, 0, 5)+'00000000000'=E.ADCD
//        LEFT JOIN AD_CD_B F on SUBSTRING(D.ADDVCD, 0, 3)+'0000000000000'=F.ADCD
//        WHERE 1=1
//        AND D.ADDVCD LIKE '${ad}%'
//        and datediff(day,tm,getdate()) = 0
//        GROUP BY D.STCD,F.ADNM,E.ADNM,g.ADNM,A.drp,B.drp,C.drp,D.BSNM,D.FRGRD,D.HNNM,D.LGTD,D.LTTD,D.RVNM,D.STLC,  D.STNM,D.STTP
//        order by D.STCD
//    </select>
//    <!--    获得测站实时降雨-->
//    <select id="getStationRain" resultType="java.util.HashMap">
//        select top ${num} h.stnm,E.adnm ,isnull(b.drp,0) drp1,isnull(c.drp,0) drp3,isnull(d.drp,0) drp6 from
//        HBS_RTDB_HB.dbo.ST_STBPRP_b h
//        left join (SELECT ADNM,ADCD from AD_CD_B where LEVELCODE =#{vCodeLevel} and SUBSTRING(ADCD,1,${vCodeLength}) =#{vCode}) E on SUBSTRING(E.ADCD,1,6)=h.ADDVCD
//        left join (select STCD,SUM(DRP) as drp from HBS_RTDB_HB.dbo.st_pptn_r where tm BETWEEN DATEADD(HOUR,-1,GETDATE()) and GETDATE()  GROUP BY STCD) b on h.STCD = b.stcd
//        left join (select STCD,SUM(DRP) as drp from HBS_RTDB_HB.dbo.st_pptn_r where tm BETWEEN DATEADD(HOUR,-3,GETDATE()) and GETDATE()  GROUP BY STCD) c on h.STCD = c.stcd
//        left join (select STCD,SUM(DRP) as drp from HBS_RTDB_HB.dbo.st_pptn_r where tm BETWEEN DATEADD(HOUR,-6,GETDATE()) and GETDATE()  GROUP BY STCD) d on h.STCD = d.stcd
//        where E.ADNM is not null
//        order by b.drp desc, c.drp desc,d.drp desc ,h.stnm
//    </select>
//    /**
//     * 获得测站实时降雨
//     * @param vCode 地区编码
//     * @param num 获得前N条
//     * @return
//     */
//    @ApiOperation("获得测站实时降雨")
//    @GetMapping("/getStationRain")
//    public ResponseResult getStationRain(@ApiParam(name = "vCode",value = "地区编码",example = "1301") @RequestParam("vCode") String vCode,
//                                         @ApiParam(name = "num",value = "获得数据条数",example = "5") @RequestParam("num")  @Min(value = 3, message = "获得条数不合法，最小为3") @Max(value = 200, message = "获得条数不合法，最大为200") int num){
//
//        return service.getStationRain(vCode,num);
//    }
}
